import req from '@/utils/request.js';
import * as URL from '@/constants/api.js';


// 导航全部分类
export function getHomeNavList() {
  return req({
    url: URL.HOME_CATEGORY,
  })
    .then((res) => res.data.result)
    .catch(() =>{});
}
// 购物车
export function getShoppingCartList() {
  return req({
    url: URL.SHOPPING_CART,
  })
    .then((res) => res.data.result)
    .catch(() =>{});
}
// 购物车 删除商品
export function delShoppingCartList(data) {
  return req({
    url: URL.SHOPPING_CART,
    method: 'DELETE',
    data,
  })
    .then((res) => res.data.msg)
    .catch(() =>{});
}
// 购物车 增加商品
export function addShoppingCartList(data) {
  return req({
    url: URL.SHOPPING_CART,
    method: 'POST',
    data,
  })
    .then((res) => res.data.msg)
    .catch(() =>{});
}
// 购物车 修改商品数量
export function updateShoppingCartNum(data) {
  return req({
    url: URL.SHOPPING_CART + '/' + data.skuId,
    method: 'PUT',
    data: {
      count: data.count,
    },
  })
    .then((res) => res.data.msg)
    .catch(() =>{});
}


// 获取轮播图数据
export function getHomeBanner(distributionSite) {
  return req({
    url: URL.HOME_BANNER,
    params: {
      distributionSite,
    },
  })
    .then((res) => res.data.result)
    .catch(() => []);
}


// 获取新鲜好物数据
export function getHomeNew(limit) {
  return req({
    url: URL.HOME_NEW,
    params: {
      limit,
    },
  })
    .then((res) => res.data.result)
    .catch(() => []);
}


// 人气推荐
export function getHomeHot() {
  return req({
    url: URL.HOME_HOT,
  })
    .then((res) => res.data.result)
    .catch(() => []);
}


// 热门品牌
export function getHomeBrand(limit) {
  return req({
    url: URL.HOME_BRAND,
    params: {
      limit,
    },
  })
    .then((res) => res.data.result)
    .catch(() => []);
}
// 产品区块
export function getHomeGoods() {
  return req({
    url: URL.HOME_GOODS,
  })
    .then((res) => res.data.result)
    .catch(() => []);
}

// 最新专区
export function getHomeSpecial(limit) {
  return req({
    url: URL.HOME_SPECIAL,
    params: {
      limit,
    },
  })
    .then((res) => res.data.result)
    .catch(() => []);
}


